package com.project.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.entity.SysOrder;
import com.project.entity.SysOrderDetail;
import com.project.mapper.SysOrderDetailMapper;
import com.project.mapper.SysOrderMapper;
import com.project.service.ISysOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wangsihan
 * @since 2021-10-08
 */
@Service
public class SysOrderServiceImpl extends ServiceImpl<SysOrderMapper, SysOrder> implements ISysOrderService {

    @Autowired
    SysOrderMapper orderMapper;

    @Autowired
    SysOrderDetailMapper orderDetailMapper;

    /**
     * 添加订单信息
     */
    @Override
    public void addOrder(SysOrder order) {
        orderMapper.addOrder(order);

        List<SysOrderDetail> list = order.getOrderDetails();

        for (SysOrderDetail orderDetail : list) {
            orderDetailMapper.addOrderDetail(orderDetail, order.getPkOrderid());
        }
    }
}
